package com.kompas.bola.application.adapter;

import java.util.List;
import com.kompas.bola.application.R;
import com.kompas.bola.application.db.CrudHelper;
import com.kompas.bola.application.model.ContentDetail;
import com.kompas.bola.application.utils.Constants;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ListRelatedAdapter extends BaseAdapter  {
	/** =========================================================================== */   
	private Activity activity;
	private List<String> data;
	private static LayoutInflater inflater = null;
	String _getGuid;
	/** =========================================================================== */   
	public ListRelatedAdapter(Activity a, List<String> _getRelated, String guid) {
		activity = a;
		data = _getRelated;
		_getGuid = guid;
		inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	/** =========================================================================== */   
	public int getCount() {
		return data.size();
	}
	/** =========================================================================== */   
	public Object getItem(int position) {
		return position;
	}
	/** =========================================================================== */   
	public long getItemId(int position) {
		return position;
	}
	/** =========================================================================== */   
	public View getView(int position, View convertView, ViewGroup parent) {
		View vi = convertView;
		
		if (convertView == null){
			vi = inflater.inflate(R.layout.list_row_related, null);	
		}

		String guid_related			= Constants.EMPTY;
		TextView guid				= (TextView) vi.findViewById(R.id.guid); // guid
		guid_related				= data.get(position);			
		guid.setText(guid_related);					
		
		TextView title 				= (TextView) vi.findViewById(R.id.title); // title		

		CrudHelper db				= new CrudHelper(activity);
		List<ContentDetail> bolaDetail	= db.getTitleByGuid(_getGuid);
		
		title.setText(bolaDetail.get(position).getTITLE_RELATED());
		
		return vi;
	}
	/** =========================================================================== */   
}
